<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('帖子内容列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>标题：</label>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                <label>类型：</label>
                                <select name="type" th:with="type=${@dict.getType('blog_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>标签：</label>
                                <select name="tags" th:with="type=${@dict.getType('blog_tags')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否热门：</label>
                                <select name="hits">
                                	<option value="">所有</option>
                                    <option value="1">是</option>
                                    <option value="2">否</option>
                                </select>
                            </li>
                            <li>
                                <label>作者：</label>
                                <input type="text" name="author"/>
                            </li>
                            <li>
                                <label>开启评论：</label>
                                <select name="allowComment">
                                    <option value="">所有</option>
                                    <option value="1">是</option>
                                    <option value="2">否</option>
                                </select>
                            </li>
                            <li>
                                <label>是否发布：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="1">是</option>
                                    <option value="2">否</option>
                                </select>
                            </li>
                            <li class="hidden">
                                <label>是否工具：</label>
                                <select name="istool">
                                    <option value="">所有</option>
                                    <option value="1">是</option>
                                    <option value="2">否</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="blog:blogcontent:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editFull()" shiro:hasPermission="blog:blogcontent:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="blog:blogcontent:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="blog:blogcontent:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-table-resizable-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('blog:blogcontent:edit')}]];
        var removeFlag = [[${@permission.hasPermi('blog:blogcontent:remove')}]];
        var childremoveFlag = [[${@permission.hasPermi('blog:blogcomment:remove')}]];
        var tagsDatas = [[${@dict.getType('blog_tags')}]];
        var typeDatas = [[${@dict.getType('blog_type')}]];
        var prefix = ctx + "blog/blogcontent";
        var commentfix = ctx + "blog/blogcomment";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                detailView: true,
                modalName: "帖子内容",
                onExpandRow : function(index, row, $detail) {
                	commentlist(index, row, $detail);
				},
                columns: [{
                    checkbox: true
                },
                {
                    field: 'contentId',
                    title: '帖子编号',
                    visible: false
                },
                {
                    field: 'title',
                    title: '标题',
                    formatter: function(value, row, index) {
                        return '<a value="'+row.contentId+'" onclick="opencontent(this)" title="'+value+'">'+value+'</a>';
                     },
                     cellStyle : function(value, row, index, field){
                         return {
                             css: {
                                 "white-space": "nowrap",
                                 "text-overflow": "ellipsis",
                                 "overflow": "hidden",
                                 "max-width":"150px"
                             }
                         };
                     }
                },
                {
                    field: 'tags',
                    title: '标签',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(tagsDatas, value);
                    }
                },
                {
                    field: 'categories',
                    title: '类别',
                    visible: false
                },
                {
                    field: 'ishot',
                    title: '是否上热门',
                    visible: false,
                    formatter : function(value, row, index) {
						if (value == '1') {
							return '<span class="label label-primary">是</span>';
						} else if(value == '2'){
							return '<span class="label label-warning">否</span>';
						} else{
							return '<span class="label label-danger">未知</span>';
						}
                    }
                },
                {
                    field: 'allowComment',
                    title: '开启评论',
                    formatter : function(value, row, index) {
						if (value == '1') {
							return '<span class="label label-primary">是</span>';
						} else if(value == '2'){
							return '<span class="label label-warning">否</span>';
						} else{
							return '<span class="label label-danger">未知</span>';
						}
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter : function(value, row, index) {
						if (value == '1') {
							return '<span class="label label-primary">发布</span>';
						} else if(value == '2'){
							return '<span class="label label-warning">草稿</span>';
						} else{
							return '<span class="label label-danger">未知</span>';
						}
                    }
                },
                {
                    field: 'istool',
                    title: '是否为工具',
                    visible: false,
                    formatter : function(value, row, index) {
						if (value == '1') {
							return '<span class="label label-primary">是</span>';
						} else if(value == '2'){
							return '<span class="label label-warning">否</span>';
						} else{
							return '<span class="label label-danger">未知</span>';
						}
                    }
                },
                {
                    field: 'createdId',
                    title: '创建人id',
                    visible: false
                },
                {
                    field: 'author',
                    title: '作者账号'
                },
                {
                    field: 'editId',
                    title: '最近修改人id',
                    visible: false
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(typeDatas, value);
                     },
                     visible: false
                },
                {
                    field: 'createDate',
                    title: '创建时间'
                },
                {
                    field: 'editDate',
                    title: '修改时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.contentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.contentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        //评论列表
        commentlist = function(index, row, $detail) {
        	var commentTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
        	$(commentTable).bootstrapTable({
                url: commentfix + "/childlist",
                method: 'post',
                contentType: "application/x-www-form-urlencoded",
                childupdateUrl: commentfix + "/edit/{id}",
                childremoveUrl: commentfix + "/remove",
                pagination: true,//显示分页
                modalName: "评论详情",
                sidePagination: "client",
                pageNumber:1,
                pageSize: 10,
                sortName: "commentId",
		        sortOrder: "desc",
                queryParams:{
		            "contentId" : row.contentId
		        },
                columns: [{
                    checkbox: true
                },
                {
                    field: 'commentId',
                    title: '评论编号',
                    visible: false
                },
                {
                    field: 'userId',
                    title: '评论者id',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '评论者'
                },
                {
                    field: 'content',
                    title: '评论内容'
                },
                {
                    field: 'createDate',
                    title: '评论时间'
                },
                {
                    field: 'pid',
                    title: '被回复评论人id',
                    visible: false
                },
                {
                    field: 'contentId',
                    title: '评论的帖子id',
                    visible: false
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter : function(value, row, index) {
						if (value == '1') {
							return '<span class="label label-primary">评论</span>';
						} else if(value == '2'){
							return '<span class="label label-warning">回复</span>';
						} else{
							return '<span class="label label-danger">未知</span>';
						}
                    }
                },
                {
                    field: 'plnrid',
                    title: '被回复评论内容id',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        //actions.push('<a class="btn btn-success btn-xs ' + childeditFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.commentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + childremoveFlag + '" href="javascript:void(0)" onclick="removechild(\'' + row.commentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            });
        };
        
        function opencontent(obj){
        	window.open('/blog/open/post/'+$(obj).attr("value"));
        }
        
        function removechild(id){
        	$.modal.confirm("确定删除该条评论信息吗？", function() {
                var url = commentfix+"/remove";
           	    var data = { "ids": id };
           	    $.operate.submit(url, "post", "json", data);
        	});
        }
    </script>
</body>
</html>